import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class DemoService {


    @Cacheable(cacheNames = "demo", key = "#id")
    public String getData(String id) {
        // 模拟从数据库获取数据
        //System.out.println("Fetching data from database...");
        return id;
    }

    @CachePut(value = "demo", key = "#id")
    public String updateData(String id, String data) {
        // 模拟更新数据到数据库
        System.out.println("Updating data in database...");
        return data;
    }

    @CacheEvict(value = "demo", key = "#id")
    public void deleteData(String id) {
        // 模拟从数据库删除数据
        System.out.println("Deleting data from database...");
    }
}
